package com.auxgroup.smarthome.repo;

import com.auxgroup.smarthome.entity.AppHomeDistanceEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by root on 17-7-25.
 */
public interface AppHomeDistanceRepo extends JpaRepository<AppHomeDistanceEntity, String> {

    AppHomeDistanceEntity findByDeviceIdAndUIdAndOnIsTrue(String deviceId, String uid);
    /**
     * Find by device id and u id app home distance entity.
     *
     * @param deviceId the device id
     * @param uid      the uid
     * @return the app home distance entity
     */
    AppHomeDistanceEntity findByDeviceIdAndUId(String deviceId, String uid);

    /**
     * Find by u id list.
     *
     * @param uid the uid
     * @return the list
     */
    @Query(value = "SELECT * FROM app_home_distance where uid = ? and is_on = true ", nativeQuery = true)
    List<AppHomeDistanceEntity> findByUId(String uid);

    /**
     * Find by distance id app home distance entity.
     *
     * @param distanceId the distance id
     * @return the app home distance entity
     */
    AppHomeDistanceEntity findByDistanceId(String distanceId);

    /**
     * Find by device id list.
     *
     * @param deviceId the device id
     * @return the list
     */
    List<AppHomeDistanceEntity> findByDeviceId(String deviceId);

}
